package com.study.cloud.simpleeurekaserver.filter;

import com.netflix.zuul.ZuulFilter;
import com.netflix.zuul.context.RequestContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.http.HttpServletRequest;

public class PreFilterZuul extends ZuulFilter {

    private static Logger LOGGER = LoggerFactory.getLogger(PreFilterZuul.class);

    @Override
    /**
     * filter的类型
     */
    public String filterType() {
        return "pre";
    }

    @Override
    /**
     *  filter执行的顺序，数字越大，执行越后
     */
    public int filterOrder() {
        return 1;
    }

    @Override
    /**
     *  是否执行这个filter
     */
    public boolean shouldFilter() {
        return true;
    }

    @Override
    /**
     * 执行类内容
     */
    public Object run() {
        HttpServletRequest request = RequestContext.getCurrentContext().getRequest();
        String remoteHost = request.getRemoteHost();
        PreFilterZuul.LOGGER.info("请求的Host：{"+ remoteHost+"}");
        return null;
    }
}
